package com.atguigu.gmall;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.product.service.SpuManageService;
import com.atguigu.gmall.product.service.impl.SpuManageServiceImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
@EnableDiscoveryClient
public class ProductApp implements CommandLineRunner {
    public static void main(String[] args) {
//        ConfigurableApplicationContext run = SpringApplication.run(ProductApp.class);
//        SpuManageService bean = run.getBean(SpuManageService.class);
        SpringApplication.run(ProductApp.class);
    }


    @Autowired
    private RedissonClient redissonClient;

    /**
     * 应用启动后执行,初始化布隆过滤器
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        System.out.println("springboot应用启动后执行");
        //1.创建布隆过滤器
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
        //2.为布隆过滤器指定数据规模,误判率
        bloomFilter.tryInit(100000, 0.03);
    }
}
